package org.kjtc.mapper;

import org.apache.ibatis.annotations.*;
import org.kjtc.entity.WxChargingstationEntity;
import org.kjtc.entity.WxCollectionEntity;

import java.util.List;

@Mapper
public interface WxChargingstationMapper {
    int deleteByPrimaryKey(String chargingstationid);

    int insert(WxChargingstationEntity record);

    int insertSelective(WxChargingstationEntity record);
    @Select("    select *  from wx_collection  WHERE openid = #{openid} and chargingStationId = #{chargingStationId}")
    WxCollectionEntity selectCollection(WxCollectionEntity wxCollection);
    @Select("select   ChargingStationID, Stage, ChargingStationNo, ChargingStationIconName, ChargingStationShortName, \n" +
            "ChargingStationName, ChargingStationAddress, Longitude, Latitude, BranchCompanyID, \n" +
            "ChargingStationType, BulidStatus, Pay, CreateUser, CreateDTTM, UpdateUser, UpdateDTTM from chargingstation\n" +
            "union all\n" +
            "SELECT  ChargingStationID, Stage, ChargingStationNo, ChargingStationIconName, ChargingStationShortName, \n" +
            "ChargingStationName, ChargingStationAddress, Longitude, Latitude, BranchCompanyID, \n" +
            "ChargingStationType, BulidStatus, Pay, CreateUser, CreateDTTM, UpdateUser, UpdateDTTM FROM chargingstation_kjtc")
    WxChargingstationEntity selectByPrimaryKey(String chargingstationid);

    @Select("SELECT  chargingstation.*,IFNULL(wx.Enabled,0) as Enabled  from (\n" +
            "select * from chargingstation\n" +
            "union all\n" +
            "SELECT * FROM chargingstation_kjtc\n" +
            ")   chargingstation \n" +
            " LEFT JOIN  \n" +
            "(SELECT * from   wx_collection where openid = #{openid}) wx ON  wx.ChargingStationID = chargingstation.ChargingStationID\n" +
            "\n")
    List<WxChargingstationEntity> selectList(@Param("openid") String openid);

    int updateByPrimaryKeySelective(WxChargingstationEntity record);

    int updateByPrimaryKey(WxChargingstationEntity record);
    @Insert(" insert into wx_collection (openid,chargingStationId ,enabled , createUser,createDttm ,updateUser ,updateDttm )\n" +
            " values (#{openid},#{chargingStationId} ,#{enabled} , #{createUser},#{createDttm} ,#{updateUser} ,#{updateDttm} )")
    int insertCollection(WxCollectionEntity wxCollectionEntity);
    @Update("UPDATE wx_collection SET enabled = #{enabled} ,updateUser = #{updateUser} ,updateDttm =#{updateDttm} \n" +
            " WHERE openid = #{openid} and chargingStationId = #{chargingStationId}")
    int updateCollection(WxCollectionEntity wxCollection);
}